package com.tencent.wuyanzu.whattoeat;


import android.content.Intent;
import android.os.Bundle;

import android.app.Activity;

import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.tencent.wuyanzu.whattoeat.Entity.Food;
import com.tencent.wuyanzu.whattoeat.util.ViewImageLoadURL;

import org.w3c.dom.Text;


public class FoodDetailActivity extends Activity {
  private   Boolean isChoose=false;

  private TextView foodThurmUpTV=null;
  private TextView foodThurmDownTV=null;
  private TextView foodNameTV=null;
  private TextView foodPriceTV=null;
  private TextView foodRestaurantNameTV=null;
  private TextView foodLocationInfoTV=null;
  private TextView foodDescTV=null;
  private ImageView foodImageIV=null;

  Food selectFood=null;

    Button popupButtonBtn;
    MyPopUpWindows popUpWindow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_food_detail);
        Intent intent=getIntent();
        Bundle bundle=intent.getExtras();
        isChoose=bundle.getBoolean("isChoose");

        foodThurmDownTV=(TextView)findViewById(R.id.food_detail_thurm_down_number);
        foodThurmUpTV=(TextView)findViewById(R.id.food_detail_thurm_up_number);

        foodNameTV=(TextView)findViewById(R.id.food_detail_name);
        foodPriceTV=(TextView)findViewById(R.id.food_detail_price);
        foodRestaurantNameTV=(TextView)findViewById(R.id.food_detail_restaurant_name);
        foodLocationInfoTV=(TextView)findViewById(R.id.food_detail_location_info);
        foodDescTV=(TextView)findViewById(R.id.food_detail_description);
        foodImageIV=(ImageView)findViewById(R.id.food_detail_food_imagine);


        selectFood=(Food) getIntent().getExtras().get("foodDetail");
        foodNameTV.setText(selectFood.getName());
        //foodPriceTV.setText(selectFood.getPrice());
        foodRestaurantNameTV.setText(selectFood.getRestaurant());
        foodLocationInfoTV.setText(selectFood.getAddress());
        foodDescTV.setText(selectFood.getDescription());
        foodThurmUpTV.setText(""+selectFood.getUp());
        foodThurmDownTV.setText(""+selectFood.getDown());


        ViewImageLoadURL bitmapLoadURL=new ViewImageLoadURL();
        bitmapLoadURL.execute(selectFood.getUrl(), foodImageIV);


        popupButtonBtn = (Button) findViewById(R.id.popup_button);
        popupButtonBtn.setOnClickListener(new View.OnClickListener(){
            public void onClick(View view){
                popUpWindow = new MyPopUpWindows(FoodDetailActivity.this,null);

                WindowManager.LayoutParams lp = getWindow().getAttributes();
                lp.alpha = 0.5f;
                getWindow().setAttributes(lp);

                popUpWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                    @Override
                    public void onDismiss() {
                        WindowManager.LayoutParams lp = getWindow().getAttributes();
                        lp.alpha = 1f;
                        getWindow().setAttributes(lp);
                    }
                });
                popUpWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
            }
        });

    }
    @Override

    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        if(isChoose) {
            popupButtonBtn.performClick();
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        if(isChoose) {
            popUpWindow.dismiss();
        }
    }
}
